import { constantRoutes, asyncRouter } from '@/router'
const state = {
    //保存动态路由和静态路由
    routes: constantRoutes

};

const mutations = {
    setRouters(state, payload) {
        // 把传进来新的路由加上静态路由一起合并成一个新数组
        state.routes = [...constantRoutes, ...payload]
    }
};
const actions = {
    getRouters(context, menus) {
        // 根据所有的动态路由过滤出来的
        let routes = asyncRouter.filter(item => menus.includes(item.name))
        routes.push({ path: '*', redirect: '/404', hidden: true })
        context.commit('setRouters', routes)
        return routes
    }
}



export default {
    namespaced: true,
    state,
    mutations,
    actions
}